const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
var fs = require('fs');
const CleanWebpackPlugin = require('clean-webpack-plugin');
var pathUrl = 'dist';
module.exports = {
    mode: "development",
    // entry: {
    //     index: './js/index.js',
    //     admin: './js/admin.js'
    // },
    entry: () => new Promise((resolve) => {
        var obj = {};
        fs.readdir('./js', (err, data) => {
            if (err) throw err;
            data.forEach(v => {
                if(v != 'forEachFile.js'){
                    console.log(v);
                    obj[`${v.split('.')[0]}`] = './js/' + v;
                }
            });
            resolve(obj);
        });
    }),
    output: {
        path: path.resolve(__dirname, pathUrl),
        filename: '[name].js'
    },
    plugins: [
        new CleanWebpackPlugin([pathUrl]),  //先清除编译的文件夹 => dist
        new HtmlWebpackPlugin({
            filename: 'index.html',   //输出HTML文件名字
            template: 'index.html',
            chunks: ['index']
        }),
        new HtmlWebpackPlugin({
            filename: 'admin.html',
            template: 'admin.html',
            // chunks: ['admin']
        })
    ]
};